package com.pickup.controller;

import com.pickup.download.FileDownload;
import com.pickup.filter.MusicFilter;
import com.pickup.pojo.MusicPojo;
import com.pickup.server.MusicServer;
import com.pickup.vo.JSONResult;
import com.pickup.vo.MusicVo;
import com.pickup.vo.ResultMusicVo;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController

@CrossOrigin(origins = "*")
@Slf4j
public class MusicController {

    @Autowired
    public MusicServer musicServer;



    @PostMapping("/getSongUrl")
    public JSONResult getSongUrl(@RequestBody MusicVo musicVo) throws Exception {
        if (StringUtils.isEmpty(musicVo)){
            return JSONResult.build(500, "求输入搜索条件！", null);
        }
        MusicFilter musicFilter = new MusicFilter(musicVo.getName(), musicVo.getSong());
        List<MusicPojo> musicPojoS = musicServer.NeteaseJson(musicFilter);
        log.info("getSongUrl{}", musicFilter);
        if (!StringUtils.isEmpty(musicPojoS)){
            return JSONResult.build(200, "搜索成功！", musicPojoS);
        }
        return JSONResult.build(500, "搜索失败！", null);
    }



}